//
//  ShoppingCarTableViewCell.m
//  CenturyInterconnection
//
//  Created by Tian Wei You on 16/4/11.
//  Copyright © 2016年 Shanghai DuRui Information Technology Company. All rights reserved.
//

#import "ShoppingCarTableViewCell.h"


@interface ShoppingCarTableViewCell()<AddNumberViewDelegate>

@property(nonatomic,assign)CGFloat number;

@end

@implementation ShoppingCarTableViewCell


- (void)awakeFromNib {
    _addNum=[self viewWithTag:111];
    if (!_addNum) {
        UIButton*button=[self viewWithTag:9];

        _addNum=[[AddNumberView alloc]initWithFrame:CGRectMake(button.right, 115, KScreenWidth/2, 50)];
    
        _addNum.backgroundColor=RGBCOLOR(243, 243, 243, 1);

//        [_addNum mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.mas_equalTo(button.mas_right);
//            make.top.mas_equalTo(button.mas_top);
//        
//        }];
        
        _addNum.tag=111;
    }
    
    _addNum.delegate=self;
    _addNum.numberLab.font=[UIFont systemFontOfSize:20];
    
    [self addSubview:_addNum];
    
}

- (void)deleteBtnAction:(UIButton *)sender addNumberView:(AddNumberView *)view{
    
//    if (self.number>1) {
//        self.number--;
//        _addNum.numberString=[NSString stringWithFormat:@"%.0f",self.number];
//    }
    
    NSInteger aa= [view.numberString integerValue];
    if (aa>1&&aa<100) {
        aa--;
        _addNum.numberString=[NSString stringWithFormat:@"%ld",(long)aa];

    }
    
    if ([self.delegate respondsToSelector:@selector(delegateForSubNumberString:andIndexPath:)]) {
        [self.delegate delegateForSubNumberString:_addNum.numberString andIndexPath:self.indexPath];
    }
}

- (void)addBtnAction:(UIButton *)sender addNumberView:(AddNumberView *)view{
    
//    self.number++;
//    _addNum.numberString=[NSString stringWithFormat:@"%.0f",self.number];
    
   NSInteger aa= [view.numberString integerValue];
    if (aa>=1&&aa<100) {
        aa++;
        _addNum.numberString=[NSString stringWithFormat:@"%ld",(long)aa];
    }
    
    
    if ([self.delegate respondsToSelector:@selector(delegateForAddNumberString:andIndexPath:)]) {
        [self.delegate delegateForAddNumberString:_addNum.numberString andIndexPath:self.indexPath];
    }
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)layoutSubviews{
    UIButton*button=[self viewWithTag:9];
    
    _addNum.frame=CGRectMake(ACTUAL_WIDTH(185), 115, KScreenWidth-button.right, 50);
//    [_addNum mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(button.mas_right);
//        make.top.mas_equalTo(button.mas_top);
//        make.right.mas_equalTo(self.contentView.right);
//        make.bottom.mas_equalTo(self.contentView.mas_bottom);
//        
//    }];
    
    
    
}

@end
